$(function() {
	//显示菜单信息
	var head = $("#breadcrumbs");
	head.html('<ul class="breadcrumb">' +
		'<li><i class="icon-home"></i> <a href="/">首页</a><span class="divider"><i class="icon-angle-right"></i></span></li>' +
		'<li><a href="#">人事信息管理</a> <span class="divider"><i class="icon-angle-right"></i></span></li>' +
		'<li><a href="/staff">员工信息管理</a> <span class="divider"><i class="icon-angle-right"></i></span></li>' +
		'<li class="active">编辑员工</li></ul>');
	var employeeId = $('#employeeId').val();
	var version = $('#versionId').val();
	// console.info("version=",version);

	var http = new XMLHttpRequest;
	http.open("HEAD", ".", false);
	http.send(null);
	var today = new Date(http.getResponseHeader("Date"));
	var year_today = today.getFullYear();
	var month_today = (today.getMonth() + 1) < 10 ? "0" + (today.getMonth() + 1) : (today.getMonth() + 1);
	var time = year_today + '-' + month_today;



	var logMode = function() {
		if (version != '' && version != undefined) {
			return true;
		} else {
			return false;
		}
	};
	var showAlert = function(message, type, delay, callback) {
		$.globalMessenger().post({
			message: message,
			hideAfter: delay,
			type: type,
		});

		if (callback) {
			callback();
		}
	}

	$("#backBtn").click(function() {
		var hisPage = $("#hisPage").val();
		var keywords = $("#getKey").val();
		window.location.href = "/staff?hisPage=" + hisPage + "&keywords=" + encodeURIComponent(keywords);
	});
	
	var initi = function() {
		var uid = $('#userId').val();
		$.ajax({
			url: '/api/getResource?',
			type: 'get',
			data: {'uid':uid, '_t':new Date().getTime()},
			success: function(data) {
				// console.info('datadata', data);
				var flag = false;
				for (var i = 0; i < data.length; i++) {
					if (data[i].resUrl == '/api/files' && data[i].operation == 'post') {
						flag = true;
					}
				}
				if (!flag) {
					$('#attach').css('display', 'none');
				}
			},
			error: function(data) {
				alert('error');
			}
		});
		$.ajax({
			url: '/api/region/provinces',
			type: 'Get',
			success: function(data) {
				$('#province').html('');
				for (var i = 0; i < data.length; i++) {
					var model = '<option value=' + data[i].id + '>' + data[i].name + '</option>';
					$('#province').append(model);
				}
			}
		});

		$.ajax({
			url: '/api/regions/cities',
			type: 'GET',
			success: function(data) {
				for (var i = 0; i < data.length; i++) {
					var model = '<option value=' + data[i].name + '>' + data[i].name + '</option>';
					$('#registeredResidence').append(model);
				}
			}
		});
		$.ajax({
			url: '/api/item/search?',
			type: 'GET',
			data: {'_t': new Date().getTime()},
			success: function(data) {
				for (var i = 0; i < data.length; i++) {
					if (data[i].type == '职位') {
						$('#job').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
					if (data[i].type == '职位类别') {
						$('#jobCategory').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
					if (data[i].type == '试用周期') {
						$('#probationaryPeriod').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
					if (data[i].type == '薪资档级') {
						$('#salaryLevel').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
					if (data[i].type == 'BAND级') {
						$('#bandLevel').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
					if (data[i].type == '工作地点') {
						$('#workPlace').append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
					}
				}
				if (!logMode()) {
					$.ajax({
						url: '/api/employees/' + employeeId + '?',
						type: 'GET',
						data: {'_t': new Date().getTime()},
						success: function(data) {
							//console.info('data:',data);
							if (data == 'noPrivilege') {
								bootbox.alert('您没有权限查看该员工的信息！');
								return;
							}
							var data = data[0];
							// console.info('data', data.job);
							showEmployee(data);
						}
					});
				} else {
					$.ajax({
						url: '/api/log/' + version + '?',
						type: 'get',
						data: {'_t': new Date().getTime()},
						success: function(result) {
							var data = result.content;
							showEmployee(data);
							$('#saveBtn').css("display", "none");
							$('#backBtn').css("display", "none");
						}
					});
					// var data = JSON.parse(version);
					// // console.info('employee', data);
					// showEmployee(data);
					// //console.info(data.job);
					// $('#saveBtn').css("display", "none");
					// $('#backBtn').css("display", "none");
				}
			}

		});

		$('#province').change(function() {
			var proId = document.getElementById('province').value;
			$('#registeredResidence').removeAttr('disabled');
			$.ajax({
				url: '/api/region/citiy/' + proId,
				type: 'GET',
				success: function(data) {
					$('#registeredResidence').html('');
					for (var i = 0; i < data.length; i++) {
						var model = '<option value=' + data[i].name + '>' + data[i].name + '</option>';
						$('#registeredResidence').append(model);
					}
				}
			});
		});

		// $('#department').mouseover(function(e){
		// var dept = document.getElementById('department').value;
		//    DialogSwitch('showDiv','block');
		//    alert('hehe');
		// });
		// //弹出框开关控制
		//   function DialogSwitch(id,sty){
		//    var showDiv = document.getElementById(id);

		//   //此属性一定要设置
		//    showDiv.style.position="absolute"; 

		// //显示隐藏控制
		//    showDiv.style.display=sty;
		//   }

		$('.date-picker').datepicker({
			todayBtn: true,
			autoclose: true
		});

		$("#noProbation").click(function() {
			$("#probationaryPeriod").val("0");
			$("#probationaryPeriod").attr("disabled", "true");
		});

		$("#yesProbation").click(function() {
			$("#probationaryPeriod").removeAttr("disabled");
		});

		var showEmployee = function(data) {
			$("#name").val(data.name);
			var sex = document.getElementById('woman').value;
			if (data.gender == sex) {
				$('#man').removeAttr('checked');
				$('#woman').attr('checked', 'checked');
			}
			$("#idNumber").val(data.idNumber);
			$("#address").val(data.address);
			$("#email").val(data.email);

			$("#phoneNum").val(data.phone);
			$("#eduBackground").val(data.education);
			$("#registeredResidence").val(data.registeredResidence);
			$.ajax({
				url: '/api/region/province/' + data.registeredResidence,
				rtpe: 'GET',
				success: function(data) {
					for (var i = 0; i < data.length; i++) {
						$('#province').val(data[i].id);
					}
				}
			});
			$("#workPlace").val(data.workPlace);
			$("#emContactPersonAndTele").val(data.emContactPerson);

			$("#emContactPersonAndTelePhone").val(data.emContactPhone);
			$("#graduInstitutions").val(data.graduInstitutions);
			$("#birthDate").val(data.birthDate);
			$("#nodeType").val(data.residenceType);
			$("#graduateTime").val(data.graduateTime);

			$("#jobNumber").val(data.jobNumber);
			$("#contractNum").val(data.contractNum);
			$("#job").val(data.job);
			$("#jobBefore").val(data.job);
			$("#jobCategory").val(data.jobCategory);
			$("#deptId").val(data.departmentId);
			//根据orgName获取
			$.ajax({
				url: '/api/organizations/getParents/' + data.departmentId + '?',
				type: 'get',
				data: {'_t': new Date().getTime()},
				success: function(result) {
					// console.info(result);
					// console.info(result[0]);
					var parentString = "";
					for (var i = result.length - 1; i >= 0; i--) {
						if (i != 0) {
							if (result[i].orgName == "分公司") {
								continue;
							} else {
								parentString += result[i].orgName + "/";
							}

						} else {
							parentString += result[i].orgName;
						}
					}

					$("#department").val(parentString);
					$("#deptId").val(result[0].id);

				}
			});
			$('#empState').val(data.state);
			$("#entryTime").val(data.entryTime);
			$("#departureTime").val(data.departureTime);
			$("#dateOfCStart").val(data.dateOfCStart);
			$("#dateOfCEnd").val(data.dateOfCEnd);

			$("#dateOfRenewalStart").val(data.dateOfRenewalStart);
			$("#dateOfRenewalEnd").val(data.dateOfRenewalEnd);
			$("#bandLevel").val(data.bandLevel);
			$("#salaryBefore").val(data.currentSalary);
			$("#currentSalary").val(data.currentSalary);
			$("#salaryLevel").val(data.salaryLevel);

			$("#bankCardNum").val(data.bankCardNum);
			$("#housingFundCard").val(data.housingFundCard);
			$("#smInsuranceCard").val(data.smInsuranceCard);
			$("#ifProbation").val(data.ifProbation);
			var probation = document.getElementById('noProbation').value;
			if (data.ifProbation == probation) {
				$('#yesProbation').removeAttr('checked');
				$('#noProbation').attr('checked', 'checked');
			}
			if (data.ifProbation === "0") {
				$("#probationaryPeriod").attr("disabled", "disabled");
			}
			$("#probationaryPeriod").val(data.probationaryPeriod);

			$("#confirmationDate").val(data.confirmationDate);
			$("#lastDateOfPromotion").val(data.lastDateOfPromotion);
			$("#lastDateOfExamination").val(data.lastDateOfExamination);
			$("#lastDateOfRise").val(data.lastDateOfRise);
		};
		//获取指定id的员工信息



		$.ajax({
			url: '/api/log?',
			type: 'get',
			data: {'id':employeeId,'type':'0', '_t':new Date().getTime()},
			success: function(data) {
				//console.info('data:::::', data);
				showLog(data);
			},
			error: function(data) {
				alert('error', data);
			}
		});

		var showLog = function(data) {
			if (data.length == 0) {
				$('#logTip').html("<div class='alert alert-warning' style='margin-top:-20px;'>未能搜索到相关信息</div>");
			} else {
				$('#logTip').html('');
			}
			$.each(data, function(i, item) {
				var log = {
					id: item.id,
					updateDate: item.updateDate,
					name: item.name,
					operation: item.operation,
					versionNo: i,
					content: item.content
				};
				var model = "<tr><td class='center'><input type=hidden id=empHisId value={{id}}>{{updateDate}}</td>" +
					"<td class='center'>{{name}}</td>" +
					"<td class='center'>{{operation}}</td>" +
					"<td class='center'><a id=version>{{versionNo}}</a></td></tr>";
				var $html = $(Mustache.to_html(model, log));
				$("#employeeHistory").append($html);
				//查看版本详细信息
				$html.click(function() {
					var empHisId = $html.find('#empHisId').val();
					// console.info('employeeId', employeeId);
					// return;
					$("#versionId").val(empHisId);
					window.location.href = '/staff/log?employeeId=' + employeeId + '&logId=' + empHisId;
				});
			});
		};



		$("#pageSize").change(function() {
			var key = document.getElementById("keyword").value;
			dataPage(1, key);
		});

		$('#searchBtn').click(function() {
			var key = document.getElementById("keyword").value;
			dataPage(1, key);
		});

		var dataPage = function(cpage, keyword) {
			$("#employeeRecord").html('');
			var pageSize = $("#pageSize option:selected").text();
			$.ajax({
				url: '/api/record/' + employeeId + '?',
				type: 'GET',
				data: {'pageSize':pageSize, 'cpage': cpage, 'keyword': keyword, '_t':new Date().getTime()},
				success: function(data) {
					// console.info('aaaaaaaaa:', data);
					var udata = {};
					if (data == 'noPrivilege') {
						udata = {
							count: 0,
							data: []
						};
					} else {
						udata = data;
					}
					var page;
					// $("#showCount").html("共"+ udata.count + "条记录");
					if (udata.count < pageSize) {
						page = 1;
					} else {
						page = Math.ceil(udata.count / pageSize);
					}
					var options = {
						currentPage: cpage,
						totalPages: page,
						alignment: 'right',
						count:udata.count,
						selectorId: 'pageSeletct',
						onPageChanged: function(e, oldPage, newPage) {
							dataPage(newPage, keyword);
						}
					};
					$('#paginator').bootstrapPaginator(options);
					$("#pageSeletct").change(function() {
						var page = $("#pageSeletct option:selected").val();
						$('#paginator').bootstrapPaginator("show",page);
					});
					var data = udata.data;

					if (data.length == 0) {
						$('#tip').html("<div class='alert alert-warning' style='margin-top:-20px;'>未能搜索到相关员工信息</div>");
						return;
					} else {
						$('#tip').html("");
					}

					for (var i = 0; i < data.length; i++) {
						var recordName;
						switch (data[i].flag) {
							case 1:
								recordName = "职位调整";
								break;
							case 2:
								recordName = "薪资调整";
								break;
							case 3:
								recordName = "部门调整";
								break;
							case 4:
								recordName = "合同调整";
								break;
						}
						$("#employeeRecord").append('<tr><td class="center">' + recordName + '</td><td class="center">' + data[i].content + '</td><td calss="center" data-date-format="yyyy-mm-dd">' + data[i].effectiveDate + '</td></tr>');
					}
				}
			});
		};
		dataPage(1, "");
	};
	initi();
	//取消选择部门
	$("#cancle").click(function() {
		$("#showOrgs").modal('hide');
	});
	//选择部门
	$("#chooseDept").click(function() {
		$("#showOrgs").modal("show");
		$("#chooseOrg").ligerTree({
			url: '/api/organizations/getOrgTree?_t=' + new Date().getTime(),
			method: 'get',
			checkbox: false,
			nodeWidth: 120,
			idFieldName: "id",
			parentIDFieldName: 'pid',
			slide: false,
			onClick: function(node) {
				// console.info('hehe');
				actionNodeID = node.data.id;
				$.ajax({
					url: '/api/organizations/getParents/' + actionNodeID,
					type: 'get',
					success: function(result) {
						// console.info(result);
						// console.info(result[0]);
						var parentString = "";
						for (var i = result.length - 1; i >= 0; i--) {
							if (i != 0) {
								parentString += result[i].orgName + "/";
							} else {
								parentString += result[i].orgName;
							}
						}
						if (result[0].orgType == "C") {
							alert("请选择部门");
						} else {
							$("#department").val(parentString);
							$("#deptId").val(result[0].id);
							$("#showOrgs").modal('hide');
						}
					}
				});
			}
		});
	});



	$("#tab-attachments").click(function() {
		$.ajax({
			url: '/api/files?',
			type: 'GET',
			data: {'id':employeeId, '_t':new Date().getTime()},
			success: function(data) {

				$('.files').html("");

				$(data).each(function(index, item) {
					var tmp = "<li><span class='file-no'>[附件{{_no}}]:</span><a href='/files/download?employeeId={{_cid}}&fileName={{_name}}'>{{_fileName}}</a><span class='file-size'>{{_size}}</span><i id='removeBtn' class='icon-remove'></i></li>";
					var $html = $(Mustache.to_html(tmp, {
						_no: index + 1,
						_cid: employeeId,
						_fileName: item.name,
						_name: item.name,
						_size: item.size < 1024 ? parseInt(item.size) + "kb" : parseInt(item.size / 1024) + "mb"
					}));
					$html.find("#removeBtn").click(function() {

						bootbox.confirm("是否删除文件\"" + item.name + "\"", function(result) {

							if (result == false)
								return;

							$.ajax({
								url: '/api/files?employeeId=' + employeeId + '&fileName=' + item.name,
								type: 'DELETE',
								success: function(data) {
									if (data == 'noPrivilege') {
										bootbox.alert('您没有权限,操作失败！');
										return;
									}
									$html.slideUp();
								}
							});
						});
					});
					$('.files').append($html);
				});
			},
			error: function(data) {
				showAlert("获取附件信息失败", "error", 2);
			}
		});
	});
	var uploadFilesInfo = new Array();
	//上传控件代码
	$('#file_upload').uploadifive({
		'uploadScript': '/api/files',
		'buttonClass': 'btn upload-btn',
		'buttonText': '添加附件',
		'auto': true,
		'fileSizeLimit': (1024 * 5),
		'onUploadComplete': function(file, data) {
			if (data == 'noPrivilege') {
				bootbox.alert('您没有权限,操作失败！');
				return;
			}
			data = JSON.parse(data);
			//console.info('data2:',data);
			uploadFilesInfo.push(data);

		},
		'onCancel': function(file) {
			for (var i = 0; i < uploadFilesInfo.length; i++) {
				if (file.name == uploadFilesInfo[i].name) {
					uploadFilesInfo.splice(i, i + 1);
				}
			}
		}
	});

	$('#jobChange').click(function() {
		$('#change').append("<tr style='text-align:center;'><input name='flag' type='hidden' value='1'/><td class='span4'>原职位：<select name='before' class='bootSelect span8'><option selected value=''>--请选择--</option></select></td><td class='span4'>现职位：<select class='bootSelect span8' name='now'><option selected value=''>--请选择--</option></select></td><td class='span4'>生效时间：<input class='span8'type='text' name='effectiveDate' data-date-format='yyyy-mm-dd'/></td><td class='span1' style='text-align:center'><button type='button' class='close' style='margin-bottom:12px;margin-right:25px'><i class='icon-remove' id=deleteIcon></i></button><td/></tr> ");
		$.ajax({
			url: '/api/item/search?',
			type: 'GET',
			data: {'_t': new Date().getTime()},
			success: function(data) {
				for (var i = 0; i < data.length; i++) {
					if (data[i].type == '职位') {
						$("select[name='before']").append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");
						$("select[name='now']").append("<option value='" + data[i].showValue + "'>" + data[i].showValue + "</option>");

					}
				}
			}
		});
		$("input[name='effectiveDate']").datepicker({
			autoclose: true,
			todayBtn: true
		});
		document.onclick = function() {
			var obj = event.srcElement;
			if (obj.id == "deleteIcon") {
				obj = obj.parentNode.parentNode.parentNode;
				obj.remove();
			}
		}
	});
	$('#salaryChange').click(function() {
		$('#change').append("<tr style='text-align:center;'><input name='flagS' type='hidden' value='2'/><td class='span4'>原薪资：<input name='beforeS' class='span8' type='text'/></td><td class='span4'>现薪资：<input name='nowS' class='span8' type='text' /></td><td class='span4'>生效时间：<input class='span8' type='text' name='effectiveDateS' data-date-format='yyyy-mm-dd'/></td><td class='span1' style='text-align:center'><button type='button' class='close' style='margin-bottom:12px;margin-right:25px'><i class='icon-remove' id=deleteIcon></i></button><td/></tr> ");
		$("input[name='effectiveDateS']").datepicker({
			autoclose: true,
			todayBtn: true
		});
		document.onclick = function() {
			var obj = event.srcElement;
			if (obj.id == "deleteIcon") {
				obj = obj.parentNode.parentNode.parentNode;
				obj.remove();
			}
		}
	});
	$('#deparChange').click(function() {
		$('#change').append("<tr style='text-align:center;'><input name='flagS' type='hidden' value='3'/><td class='span4'>原部门：<input name='beforeS' class='span8' type='text' id='chooseDeptBefore'/></td><td class='span4'>现部门：<input name='nowS' class='span8' type='text' id='chooseDeptNow' /></td><td class='span4'>生效时间：<input class='span8' type='text' name='effectiveDateS' data-date-format='yyyy-mm-dd'/></td><td class='span1' style='text-align:center'><button type='button' class='close' style='margin-bottom:12px;margin-right:25px'><i class='icon-remove' id=deleteIcon></i></button><td/></tr> ");
		$("#chooseDeptBefore").click(function() {
			
			$("#showOrgsBefore").modal("show");
			$("#chooseOrgBefore").ligerTree({
				url: '/api/organizations/getOrgTree?_t=' + new Date().getTime(),
				method: 'get',
				checkbox: false,
				nodeWidth: 120,
				idFieldName: "id",
				parentIDFieldName: 'pid',
				slide: false,
				onClick: function(node) {
					actionNodeID = node.data.id;
					$.ajax({
						url: '/api/organizations/getParents/' + actionNodeID,
						type: 'get',
						success: function(result) {
							var parentString = "";
							for (var i = result.length - 1; i >= 0; i--) {
								if (i != 0) {
									parentString += result[i].orgName + "/";
								} else {
									parentString += result[i].orgName;
								}
							}
							if (result[0].orgType == "C") {
								alert("请选择部门");
							} else {
								$("#chooseDeptBefore").val(parentString);
								$("#showOrgsBefore").modal('hide');
							}
						}
					});
				}
			});
		});
		$("#chooseDeptNow").click(function() {
			$("#showOrgsNow").modal("show");
			$("#chooseOrgNow").ligerTree({
				url: '/api/organizations/getOrgTree?_t=' + new Date().getTime(),
				method: 'get',
				checkbox: false,
				nodeWidth: 120,
				idFieldName: "id",
				parentIDFieldName: 'pid',
				slide: false,
				onClick: function(node) {
					actionNodeID = node.data.id;
					$.ajax({
						url: '/api/organizations/getParents/' + actionNodeID,
						type: 'get',
						success: function(result) {
							var parentString2 = "";
							for (var i = result.length - 1; i >= 0; i--) {
								if (i != 0) {
									parentString2 += result[i].orgName + "/";
								} else {
									parentString2 += result[i].orgName;
								}
							}
							if (result[0].orgType == "C") {
								alert("请选择部门");
							} else {
								$("#chooseDeptNow").val(parentString2);
								$("#showOrgsNow").modal('hide');
							}
						}
					});
				}
			});
		});
		$("input[name='effectiveDateS']").datepicker({
			autoclose: true,
			todayBtn: true
		});
		document.onclick = function() {
			var obj = event.srcElement;
			if (obj.id == "deleteIcon") {
				obj = obj.parentNode.parentNode.parentNode;
				obj.remove();
			}
		}
	});
	$('#saveBtn').click(function() {
		var dataModel = buildDataModel();
		dataModel.time = time;
		if (dataModel.name == null || dataModel.name == '') {
			bootbox.alert("请填写姓名！");
			return;
		}
		if (dataModel.idNumber == null || dataModel.idNumber == '') {
			bootbox.alert("请填写身份证号！");
			return;
		}
		if (dataModel.email == null || dataModel.email == '') {
			bootbox.alert("请填写邮箱！");
			return;
		}
		if (dataModel.phone == null || dataModel.phone == '') {
			bootbox.alert("请填写联系电话！");
			return;
		}
		if (dataModel.jobNumber == null || dataModel.jobNumber == '') {
			bootbox.alert("请填写工号！");
			return;
		}
		if (dataModel.job == null || dataModel.job == '') {
			bootbox.alert("请填写职位！");
			return;
		}
		if (dataModel.jobCategory == null || dataModel.jobCategory == '') {
			bootbox.alert("请选择职位类别！");
			return;
		}
		if (dataModel.departmentId == null || dataModel.departmentId == '') {
			bootbox.alert("请选择部门！");
			return;
		}
		if (dataModel.state == null || dataModel.state == '') {
			bootbox.alert("请选择状态！");
			return;
		}

		if (dataModel.ifProbation == "1" && (dataModel.probationaryPeriod == null || dataModel.probationaryPeriod == '')) {
			bootbox.alert("请选择试用周期！");
			return;
		}
		if (!dataModel.recordCheck) {
			bootbox.alert("请完善变更记录信息！");
			return;
		}
		//检查姓名、工号的存在性
		var name = dataModel.name;
		var jobNumber = dataModel.jobNumber;
		//console.info(dataModel);
		$.ajax({
			url: '/api/employee/all?',
			type: 'GET',
			data: {'_t':new Date().getTime()},
			success: function(data) {
				for (var i = 0; i < data.length; i++) {
					if (data[i].jobNumber == jobNumber && data[i].id != employeeId) {
						bootbox.alert('工号已存在！');
						return;
					}
				}
				updateModel(employeeId, dataModel);
			},
			error: function() {
				showAlert("更新失败", "error", 2);
			}
		});
	});

	var updateModel = function(id, data) {
		$.ajax({
			url: '/api/employees/' + id,
			type: 'PUT',
			data: data,
			success: function(result) {
				if (result == 'noPrivilege') {
					bootbox.alert('您没有权限,操作失败！');
					return;
				}
				bootbox.alert('更新成功！', function() {
					var hisPage = $("#hisPage").val();
					var keywords = $("#getKey").val();
					window.location.href = "/staff?hisPage=" + hisPage + "&keywords=" + encodeURIComponent(keywords);
				});
			},
			error: function(result) {
				bootbox.alert('更新失败！');
				
			}
		});
	};

	var buildDataModel = function() {
		var $name = $('#name').val(), //姓名
			$idNumber = $('#idNumber').val(), //身份证号
			$address = $('#address').val(), //通讯地址
			$phoneNum = $('#phoneNum').val(), //联系电话
			$eduBackground = $('#eduBackground option:selected').val(), //学历
			$registeredResidence = $('#registeredResidence option:selected').val(), //户口所在地
			$workPlace = $('#workPlace option:selected').val(), //工作地点
			$emContactPersonAndTele = $('#emContactPersonAndTele').val(), ///紧急联系人
			$graduInstitutions = $('#graduInstitutions').val(), //毕业院校
			$birthDate = $('#birthDate').val(), //出生日期
			$nodeType = $('#nodeType option:selected').val(), //户口类型
			$email = $('#email').val(), //个人邮箱
			$emContactPersonAndTelePhone = $('#emContactPersonAndTelePhone').val(), //紧急联系人电话
			$graduateTime = $('#graduateTime').val(), //毕业时间
			$position = $('#job option:selected').val(), //职位变更值
			$jobBefore = $('#jobBefore').val(), //职位
			$jobCategory = $('#jobCategory option:selected').val(), //职位类别
			$entryTime = $('#entryTime').val(), //入职时间
			$departmentbefore = $('#departmentbefore').val(),
			$departmentnow = $('#department').val(),
			$deptId = document.getElementById('deptId').value, //部门
			$departureTime = $('#departureTime').val(), //离职时间
			$jobNumber = $('#jobNumber').val(), //工号
			//==========合同保密协议?????
			$dateOfCStart = $('#dateOfCStart').val(), //合同开始时间
			// $dateOfRenewalStart = $('#dateOfRenewalStart').val(), //合同续签开始时间
			$bandLevel = $('#bandLevel option:selected').val(), //BAND级
			$currentSalary = $('#currentSalary').val(), //当前月薪变更值
			$salaryBefore = $('#salaryBefore').val(), //当前月薪
			$bankCardNum = $('#bankCardNum').val(), //银行卡号
			$contractNum = $('#contractNum').val(), //合同编号
			//==========竞业协议?????
			$dateOfCEnd = $('#dateOfCEnd').val(), //合同结束时间
			// $dateOfRenewalEnd = $('#dateOfRenewalEnd').val(), //合同续签结束时间
			$lastDateOfPromotion = $('#lastDateOfPromotion').val(), //最后一次晋级时间
			$salaryLevel = $('#salaryLevel option:selected').val(), //薪资档级
			$smInsuranceCard = $('#smInsuranceCard').val(), //社保医保卡号
			//==========劳动合同主体?????
			$probationaryPeriod = $('#probationaryPeriod option:selected').val(), //试用周期
			$confirmationDate = $('#confirmationDate').val(), //转正日期
			$lastDateOfExamination = $('#lastDateOfExamination').val(), //最后一次体检日期
			$lastDateOfRise = $('#lastDateOfRise').val(), //最后一次加薪日期
			$state = $("#empState option:selected").val(),
			$housingFundCard = $('#housingFundCard').val(); //住房公积金卡号
		// $state = $('#state').val(); //在职状态

		var $gender; //性别
		var $ifProbation; //是否有试用期
		var genders = document.getElementsByName("gender-radio");
		var ifProbations = document.getElementsByName("probation-radio");

		for (var i = 0; i < 2; i++) {
			if (genders[i].checked) {
				// alert(genders[i].value);
				$gender = genders[i].value;
			}
			if (ifProbations[i].checked) {
				// alert(ifProbations[i].value);
				$ifProbation = ifProbations[i].value;
			}
		}
		// 变更记录
		var $recordItems = [];
		var $recordCheck = true;

		var beforeArr = $("select[name='before'] option:selected");
		var nowArr = $("select[name='now'] option:selected");
		var effectiveDateArr = $("input[name='effectiveDate']");
		var flagArr = $("input[name='flag']");

		var beforeArrS = $("input[name='beforeS']");
		var nowArrS = $("input[name='nowS']");
		var effectiveDateArrS = $("input[name='effectiveDateS']");
		var flagArrS = $("input[name='flagS']");

		if (beforeArr.length > 0) {
			beforeArr.each(function(item) {
				if ($(beforeArr[item]).val() == "" || $(nowArr[item]).val() == "" || $(effectiveDateArr[item]).val() == "") {
					$recordCheck = false;
				}

				var recordData = {
					content: "职位由 " + $(beforeArr[item]).val() + " 调整为 " + $(nowArr[item]).val(),
					effectiveDate: $(effectiveDateArr[item]).val(),
					employeeId: employeeId,
					flag: $(flagArr[item]).val()
				};


				$recordItems.push(recordData);
			});
		}
		if (beforeArrS.length > 0) {
			beforeArrS.each(function(item) {
				if ($(beforeArrS[item]).val() == "" || $(nowArrS[item]).val() == "" || $(effectiveDateArrS[item]).val() == "") {
					$recordCheck = false;
				}
				var str1="";
				var str2="";
				if($(flagArrS[item]).val()==2){
					str1="薪资由 ￥";
					str2=" 调整为 ￥";
				}else if($(flagArrS[item]).val()==3){
					 str1="部门由 ";
					 str2=" 调整为 ";
				}
				var recordData = {
					content: str1 + $(beforeArrS[item]).val() + str2 + $(nowArrS[item]).val(),
					effectiveDate: $(effectiveDateArrS[item]).val(),
					employeeId: employeeId,
					flag: $(flagArrS[item]).val()
				};

				$recordItems.push(recordData);
			});
		}

		// 变更记录end
		// console.info('--$recordCheck--', $recordCheck);
		// console.info('--$recordItems--', $recordItems);
		var model = {};
		model.name = $name;
		model.gender = $gender;
		model.idNumber = $idNumber;
		model.address = $address;
		model.email = $email;

		model.phone = $phoneNum;
		model.education = $eduBackground;
		model.registeredResidence = $registeredResidence;
		model.workPlace = $workPlace;
		model.emContactPerson = $emContactPersonAndTele;

		model.emContactPhone = $emContactPersonAndTelePhone;
		model.graduInstitutions = $graduInstitutions;
		model.birthDate = $birthDate;
		model.residenceType = $nodeType;
		model.graduateTime = $graduateTime;

		model.jobNumber = $jobNumber;
		model.contractNum = $contractNum;
		model.job = $position;
		model.jobBefore = $jobBefore;
		model.jobCategory = $jobCategory;
		model.departmentId = $deptId;
		model.departmentBefore = $departmentbefore;
		model.departmentNow = $departmentnow;

		model.state = $state;
		model.entryTime = $entryTime;
		model.departureTime = $departureTime;
		model.dateOfCStart = $dateOfCStart;
		model.dateOfCEnd = $dateOfCEnd;

		// model.dateOfRenewalStart = $dateOfRenewalStart;
		// model.dateOfRenewalEnd = $dateOfRenewalEnd;
		model.bandLevel = $bandLevel;
		model.currentSalary = $currentSalary * 1;
		model.salaryBefore = $salaryBefore * 1;
		model.salaryLevel = $salaryLevel;

		model.bankCardNum = $bankCardNum;
		model.housingFundCard = $housingFundCard;
		model.smInsuranceCard = $smInsuranceCard;
		model.ifProbation = $ifProbation;
		model.probationaryPeriod = $probationaryPeriod;

		model.confirmationDate = $confirmationDate;
		model.lastDateOfPromotion = $lastDateOfPromotion;
		model.lastDateOfExamination = $lastDateOfExamination;
		model.lastDateOfRise = $lastDateOfRise;
		model.file = uploadFilesInfo;
		// 变更记录
		model.recordCheck = $recordCheck;
		model.recordItems = $recordItems;

		return model;
	};
});